package com.hzeport.bgs22emduty.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.hzeport.bgs22emduty.common.utils.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public enum SetDutyTypeEnum implements BaseEnum{
    //工作日班、周末、节假日及重要时期
    TYPE_RC("1","工作日班"),
    TYPE_ZMB("2","节假日"),
    TYPE_ZYB("3","重要日"),
    TYPE_ZM("4","周末班");
    private String code;
    private String description;
    SetDutyTypeEnum(){};
    SetDutyTypeEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }
    @Override
    public String toString() {
        return this.getValue();
    }
    @Override
    public String getValue() {
        return code;
    }

    public String getDesc() {
        return description;
    }

    @Override
    public  BaseEnum getEnum(String value) {
        for(BaseEnum v : values())
            if(v.getValue().equalsIgnoreCase(value)) return v;
        throw new IllegalArgumentException();
    }
    public String getValueByCode(String code){
        for(SetDutyTypeEnum v : values())
            if(v.getValue().equalsIgnoreCase(code)) return v.getDescription();
        return code;
    }

    public String getCodeByValue(String value){
        for(SetDutyTypeEnum v : values())
            if(v.getDescription().equalsIgnoreCase(value)) return v.getValue();
        return value;
    }
    public Map<String,Object> toMap(){
        Map<String,Object> map = new HashMap<>();
        map.put("code",getValue());
        map.put("description ",getDescription());
        return map;
    }

    public static String getDescByCode(String code) {
        if (StringUtils.isNotEmpty(code)) {
            for (SetDutyTypeEnum myEnum : SetDutyTypeEnum.values()) {
                if (StringUtils.equals(myEnum.getValue(), code)) {
                    return myEnum.getDesc();
                }
            }
        }
        return "";
    }

    public static List<String> getAllCode() {
        return Arrays.asList(SetDutyTypeEnum.values()).stream().map(i->i.getCode()).collect(Collectors.toList());
    }

    private String getCode() {
        return this.code ;
    }

    @JsonValue
    public String getDescription() {
        return description;
    }

}
